/*
	The MIT License

	Copyright (c) 2010 IFMO/GameDev Studio

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/


#pragma once

/*-----------------------------------------------------------------------------
	Scene stuff :
-----------------------------------------------------------------------------*/

enum ERScenePass_t {
		SCENE_Z_PASS,			//	early Z pass
		SCENE_G_PASS,			//	g-buffer pass
		SCENE_SM_PASS,			//	shadow map pass
		SCENE_GLOW_PASS,		//	glowing stuff
		SCENE_TRANS_PASS,		//	translucent stuff
		
		SCENE_PASS_MAX,			//	number of passes, not used
	};

class	ERScene : public IDSScene {
	public:
								ERScene			( ED3DRenderSystem *rs );
								~ERScene		( void );

		virtual	void			RenderScene		( void );
		
		virtual IPxRSLight		AddLight		( const ERendLightDesc_s *light_desc );
		virtual IPxRSEntity		AddEntity		( IPxTriMesh mesh, const EVec4 &pos, const EQuat &orient );
		virtual void			RemoveLight		( IPxRSLight light );
		virtual void			RemoveEntity	( IPxRSEntity entity );
		
		virtual void			AddStaticMesh	( const IPxTriMesh mesh, const EVec4 &pos, const EQuat &orient );

		virtual void			SetView			( const EVec4 &position, const EQuat &orient );
		virtual void			SetProjection	( float znear, float zfar, float width, float height );
		virtual void			SetAmbientLevel	( const EVec4 &color );

		virtual void			DebugLine		( const EVec3 &v0, const EVec3 &v1, const EVec4 &color  );
		
		virtual void			DebugTexture	( float x, float y, float w, float h, IPxTexture tex );

		virtual void			AddGFXSprite	( const ERSGFXSprite_s &sprite );
		virtual void			AddGFXStrip		( const ERSGFXStrip_s &strip );
		
	protected:
		void					InitDebugRender		( void );
		
	public:
		void					RenderDebug			( void );
		void					RenderSimple		( void );
		
		void					RenderDeferred		( IPxTexture *gbuffer, IPxTexture gbuffer_depth );
		void					RenderLighting		( IPxTexture target );
		void					RenderEmissive		( IPxTexture target );
		void					RenderDistortive	( IPxTexture dudv_buffer );
		void					RenderTranslucent	( IPxTexture target );
		void					RenderWireframe		( void );
		void					RenderShadowMap		( const EMatrix4 &view, const EMatrix4 &proj, IPxTexture sm_color, IPxTexture sm_depth );
		void					RenderGFX			( IPxTexture target );
		void					RenderHDR			( void );
		
	protected:
		
	public:	
		EMatrix4				view_matrix;
		EMatrix4				proj_matrix;
		EVec4					view_position;
		
	public:
		static int	ReloadShaders		( lua_State *L );
	
		ED3DRenderSystem		*rs;
		IDirect3DDevice9		*d3ddev;
		
		IPxDraw2D				draw2d;
	
		hard_ref<ERSShadingSystem>	sshs;
		hard_ref<ERSLightRenderer>	light_rend;
		hard_ref<ERSScreenFX>		scr_fx;
		hard_ref<ERSGFXSystem>		gfx;
		
		IPxRTManager		rtm;
		
		vector<ERSLine_s>		debug_lines;
		
		vector<IPxRSEntity>	entities;
		vector<IPxRSLight>	lights;
		
		vector<ERSGFXSprite_s>	sprites;
		vector<ERSGFXStrip_s>	strips;
		
		IPxVar	rs_wireframe;


	};
	